home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 3006 / 3006.xpi / components / dhTestProbe.js < prev    next >
Text File  |  2010-01-15  |  5KB  |  152 lines

  1. /******************************************************************************
  2.  *            Copyright (c) 2006-2009 Michel Gutierrez. All Rights Reserved.
  3.  ******************************************************************************/
  4.  
  5. /**
  6.  * Constants.
  7.  */
  8.  
  9. const NS_TESTPROBE_CID = Components.ID("{ae26dbda-4e3b-448a-8479-a1222dbed1a3}");
  10. const NS_TESTPROBE_PROG_ID = "@downloadhelper.net/test-probe;1";
  11. const DHNS = "http://downloadhelper.net/1.0#";
  12.  
  13. var Util=null;
  14.  
  15. /**
  16. * Object constructor
  17. */
  18. function TestProbe() {
  19.     try {
  20.         dump("[TestProbe] constructor\n");
  21.         var core=Components.classes["@downloadhelper.net/core;1"].
  22.             getService(Components.interfaces.dhICore);
  23.         core.registerProbe(this);
  24.         this.count=0;
  25.     } catch(e) {
  26.         dump("[TestProbe] !!! constructor: "+e+"\n");
  27.     }
  28. }
  29.  
  30. TestProbe.prototype = {}
  31.  
  32. TestProbe.prototype.handleDocument=function(document,window) {
  33.     try {
  34.         dump("[TestProbe] handleDocument("+document.URL+")\n");
  35.         this.count++;
  36.         if(this.count%2)
  37.             return;
  38.         var desc=Components.classes["@mozilla.org/properties;1"].
  39.             createInstance(Components.interfaces.nsIProperties);
  40.         Util.setPropsString(desc,"label","["+this.count+"] "+document.URL);
  41.         this.core.addEntryForDocument(desc,document,window);
  42.     } catch(e) {
  43.         dump("!!! [TestProbe] handleDocument: "+e+"\n");
  44.     }
  45. }
  46.  
  47. TestProbe.prototype.handleRequest=function(request) {
  48. }
  49.     
  50. TestProbe.prototype.handleResponse=function(request) {
  51. }
  52.  
  53. TestProbe.prototype.QueryInterface = function(iid) {
  54.     dump("[TestProbe] QueryInterface("+iid+")\n");
  55.     if(
  56.         iid.equals(Components.interfaces.dhIProbe) ||
  57.         iid.equals(Components.interfaces.nsISupports)
  58.     ) {
  59.         return this;
  60.     }
  61.     throw Components.results.NS_ERROR_NO_INTERFACE;
  62. }
  63.  
  64. var vTestProbeModule = {
  65.     firstTime: true,
  66.     
  67.     /*
  68.      * RegisterSelf is called at registration time (component installation
  69.      * or the only-until-release startup autoregistration) and is responsible
  70.      * for notifying the component manager of all components implemented in
  71.      * this module.  The fileSpec, location and type parameters are mostly
  72.      * opaque, and should be passed on to the registerComponent call
  73.      * unmolested.
  74.      */
  75.     registerSelf: function (compMgr, fileSpec, location, type) {
  76.  
  77.         if (this.firstTime) {
  78.             this.firstTime = false;
  79.             throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
  80.         }
  81.         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  82.         compMgr.registerFactoryLocation(NS_TESTPROBE_CID,
  83.                                         "TestProbe",
  84.                                         NS_TESTPROBE_PROG_ID, 
  85.                                         fileSpec,
  86.                                         location,
  87.                                         type);
  88.     },
  89.  
  90.     unregisterSelf: function(compMgr, fileSpec, location) {
  91.         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  92.         compMgr.unregisterFactoryLocation(NS_DH_TESTPROBE_CID, fileSpec);
  93.     },
  94.  
  95.     /*
  96.      * The GetClassObject method is responsible for producing Factory and
  97.      * SingletonFactory objects (the latter are specialized for services).
  98.      */
  99.     getClassObject: function (compMgr, cid, iid) {
  100.         if (!cid.equals(NS_TESTPROBE_CID)) {
  101.             throw Components.results.NS_ERROR_NO_INTERFACE;
  102.         }
  103.  
  104.         if (!iid.equals(Components.interfaces.nsIFactory)) {
  105.             throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  106.         }
  107.  
  108.         return this.vTestProbeFactory;
  109.     },
  110.  
  111.     /* factory object */
  112.     vTestProbeFactory: {
  113.         /*
  114.          * Construct an instance of the interface specified by iid, possibly
  115.          * aggregating it with the provided outer.  (If you don't know what
  116.          * aggregation is all about, you don't need to.  It reduces even the
  117.          * mightiest of XPCOM warriors to snivelling cowards.)
  118.          */
  119.         createInstance: function (outer, iid) {
  120.             if (outer != null) {
  121.                 throw Components.results.NS_ERROR_NO_AGGREGATION;
  122.             }
  123.     
  124.             if(Util==null) 
  125.                 Util=Components.classes["@downloadhelper.net/util-service;1"]
  126.                     .getService(Components.interfaces.dhIUtilService);
  127.  
  128.             return new TestProbe().QueryInterface(iid);
  129.         }
  130.     },
  131.  
  132.     /*
  133.      * The canUnload method signals that the component is about to be unloaded.
  134.      * C++ components can return false to indicate that they don't wish to be
  135.      * unloaded, but the return value from JS components' canUnload is ignored:
  136.      * mark-and-sweep will keep everything around until it's no longer in use,
  137.      * making unconditional ``unload'' safe.
  138.      *
  139.      * You still need to provide a (likely useless) canUnload method, though:
  140.      * it's part of the nsIModule interface contract, and the JS loader _will_
  141.      * call it.
  142.      */
  143.     canUnload: function(compMgr) {
  144.         return true;
  145.     }
  146. };
  147.  
  148. function NSGetModule(compMgr, fileSpec) {
  149.     return vTestProbeModule;
  150. }
  151.  
  152.